pp108 : addItems Method

addItems Method


This method adds a list of items under the root node or the selected node of the tree.

Syntax


oNewItemsArray = treeID.root.addItems(oItemsDefinitionArray)

When called from a node other than root, the syntax is as follows:

oNewItemsArray = treeNode.addItems(oItemsDefinitionArray)

Parameters

Parameter

Description

oItemsDefinitionArray

Required. Object that points to an array containing XMLDOM objects that contains the items to be added in the tree node.


Return Value

Returns an array of newly added items .

Remarks

The return array contains, at the same relative location, the tree items that were created from the XMLDOM objects. If the XMLDOM object did not result in a tree item, null is returned at the position in the array. Adding items in bulk through this method enhances the performance of the tree.

Example

The following example shows the usage of the above defined method.

<!-- Template of the item to be added to the tree -->
<script type="cordys/xml" id="newItemTemplate">
    <Favourites>
        <Favourite>
             <id>favourite1</id>
             <description>MSDN</description>
             <caption>MSDN</caption>
        </Favourite>
        <Favourite>
             <id>favourite2</id>
             <description>JavaScript</description>
             <caption> JavaScript</caption>
        </Favourite>
        <Favourite>
             <id>favourite3</id>
             <description>CSharp</description>
             <caption>CSharp</caption>
        </Favourite>
        <Favourite>
             <id>favourite4</id>
             <description>Jscript.net</description>
             <caption>Jscript.net</caption>
        </Favourite>
    </Favourites>
</script>
//Function that adds item to the existing tree
function addNewItem()
{
   //Add a list of items, that depends on the new schema
   var newItemsArray = cordys.selectXMLNodes(newItemTemplate.XMLDocument,"./*[local-name()='Favourites']/*[local-name()='Favourite']");
   //Add the items using addItems function to the selected item
   sampletree.root.addItems(newItemsArray);
   //Add the same items to the selected node also
   sampletree.getSelectedItem().addItems(newItemsArray);
    //Expand the selected item after addition
   sampletree.getSelectedItem().expand();
}

See Also

tree, treeSchema, addSchemaItem, addItem